
package com.lpf.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Slf4j
@Component // 注入Spring容器
@Aspect    // 定义切面
public class AopAnnotation {

    @Before("execution(* com.lpf.aop.service.*.*(..))")
    public void begin() {
        log.error("前置通知....");
    }

    @After("execution(* com.lpf.aop.service.*.*(..))")
    public void commit() {
        log.error("后置通知....");
    }

    @AfterReturning("execution(* com.lpf.aop.service.*.*(..))")
    public void afterRun() {
        log.error("运行通知....");
    }

    @AfterThrowing("execution(* com.lpf.aop.service.*.*(..))")
    public void afterThrowing() {
        log.error("异常通知");
    }

    @Around("execution(* com.lpf.aop.service.*.*(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.error("我是环绕通知-前");
        proceedingJoinPoint.proceed();
        log.error("我是环绕通知-后");
    }

}
